package com.example.pingapplication2.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.pingapplication2.R;
import com.example.pingapplication2.databinding.FragmentMainBinding;
import com.example.pingapplication2.net.INetListener;
import com.example.pingapplication2.viewModel.StateViewModel;

/**
 * 主fragment，主要负责跳转到其余2个fragment
 */
public class MainFragment extends Fragment implements INetListener {
    FragmentMainBinding fragmentMainBinding;
    StateViewModel mStateViewModel;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_main, container, false);
        fragmentMainBinding = FragmentMainBinding.bind(view);

        //viewModel的初始化
        mStateViewModel = new ViewModelProvider(requireActivity()).get(StateViewModel.class);

        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        fragmentMainBinding.toCountFragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NavController navController = Navigation.findNavController(view);
                navController.navigate(R.id.action_mainFragment_to_countDownFragment);
            }
        });

        fragmentMainBinding.toMaxFragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NavController navController = Navigation.findNavController(view);
                navController.navigate(R.id.action_mainFragment_to_maxFailFragment);
            }
        });
    }



    @Override
    public void pingSuccess() {

    }

    @Override
    public void pingFailure() {

    }
}